package pt.fct.mpc.lastfm;

import pt.fct.mpc.lastfm.search.LastfmSearchActivity;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class LastfmMenuActivity
	extends ListActivity
{
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		
		String[] menu_items = 
			getResources().getStringArray(R.array.lastfm_menu_array);
		setListAdapter(
			new ArrayAdapter<String>(this, R.layout.list_item, menu_items));
		
		ListView lv = getListView();
		lv.setTextFilterEnabled(true);
		
		lv.setOnItemClickListener(
			new OnItemClickListener()
			{
				@Override
				public void onItemClick(AdapterView<?> parent, View view,
					int position, long id)
				{
					Context context = getApplicationContext();
					
					int search_type;
					
					switch (position)
					{
						case 0: // Find Artist
							search_type = LastfmSearchActivity.SEARCH_ARTIST;
							break;
							
						case 1: // Find Album
							search_type = LastfmSearchActivity.SEARCH_ALBUM;
							break;
							
						default: // What's up, dude?
							search_type = LastfmSearchActivity.SEARCH_ALL;
							break;
					}
					
					Bundle search_params = new Bundle();
					search_params.putInt("type", search_type);
					
					Intent intent = 
						new Intent(context, LastfmSearchActivity.class);
					intent.putExtras(search_params);
					
					startActivityForResult(intent, 0);
				}
			}
		);
	}

}
